/**
 * CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

package com.cmcc.zysoft.infocollection.mobile.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cmcc.zysoft.infocollection.common.BaseController;
import com.cmcc.zysoft.infocollection.mobile.service.MAdviseService;
import com.cmcc.zysoft.infocollection.mobile.service.MInterfaceLogService;
import com.cmcc.zysoft.infocollection.mobile.service.MSystemUserService;
import com.cmcc.zysoft.infocollection.model.SystemUser;

/**
 * @author 袁凤建
 * <br />邮箱: yuan.fengjian@ustcinfo.com
 * <br />描述: MAdviseController.java
 * <br />版本: 1.0.0
 * <br />日期: 2013-8-12 上午10:07:31
 * <br />CopyRight © 2012 USTC SINOVATE SOFTWARE CO.LTD All Rights Reserved.
 */

@Controller
@RequestMapping("/mobile/advise")
public class MAdviseController extends BaseController {

	/**
	 * 属性名称: mAdviseService.
	 * 类       型: MAdviseService.
	 */
	@Resource
	private MAdviseService mAdviseService;
	
	/**
	 * 属性名称: mSystemUserService.
	 * 类       型: MSystemUserService.
	 */
	@Resource
	private MSystemUserService mSystemUserService;
	
	/**
	 * 属性名称: mInterfaceLogService.
	 * 类       型: MInterfaceLogService.
	 */
	@Resource
	private MInterfaceLogService mInterfaceLogService;
	
	/**
	 * 意见反馈.
	 * @param usercode 手机号
	 * @param content 意见内容
	 * @return map
	 */
	@RequestMapping("/add.htm")
	@ResponseBody
	@Transactional
	public Map<String, Object> addAdvise(String usercode, String content) {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			List<SystemUser> list = this.mSystemUserService.findByNamedParam(new String[]{"userName", "delFlag"}, new Object[]{usercode, "0"});
			if(!list.isEmpty()) {
				SystemUser user = list.get(0);
				this.mInterfaceLogService.addLog(user.getUserId(), user.getCompanyId(), "意见反馈");
				map = this.mAdviseService.addAdvise(user.getUserId(), content, user.getCompanyId());
			} else {
				map.put("status", "2");
			}
		} catch (Exception e) {
			map.put("status", "2");
		}
		return map;
	}
}